﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using SweeperPrototype.Business.Fields;
using SweeperPrototype.Business.Keys;
using SweeperPrototype.Objects;

namespace SweeperPrototype.GUI.Positions
{
    public class PositionViewModel : BaseVM
    {
        private static readonly PropertyChangedEventArgs ARGS = new PropertyChangedEventArgs(null);

        public static readonly PropertyChangedEventArgs ARGS_QUANTITY = new PropertyChangedEventArgs("Quantity");
        public static readonly PropertyChangedEventArgs ARGS_ISSELECTED = new PropertyChangedEventArgs("IsSelected");

        private readonly PositionSubscription m_PositionSubscription;
        
        public PositionViewModel(PositionSubscription position_subscription)
        {
            m_PositionSubscription = position_subscription;
            m_PositionSubscription.Updated += HandlePositionUpdate; 
        }

        private void HandlePositionUpdate(PositionSubscription source,
                                          PositionSubscription.PositionUpdate new_update,
                                          PositionSubscription.PositionUpdate old_update)
        {
            // this can be detailed and sexy.
            FirePropertyChanged(ARGS);
        }

        public BookCode BookCode
        {
            get { return m_PositionSubscription.BookCode; }
        }

        public ExposureRIC RIC
        {
            get { return m_PositionSubscription.RIC; }
        }

        public Shares Quantity
        {
            get { return m_PositionSubscription.Quantity; }
        }

        public bool IsValid
        {
            get { return m_PositionSubscription.IsValid; }
        }

        private bool m_IsSelected;

        public bool IsSelected
        {
            get { return m_IsSelected; }
            set
            {
                if (m_IsSelected == value) return;

                m_IsSelected = value;
                FirePropertyChanged( ARGS_ISSELECTED );
                Console.WriteLine( "Selected!");
            }
        }

        internal PositionSubscription CorePositionSubscription { get { return m_PositionSubscription; } }
        
    }
}
